/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Filter;

import Proxy.FileInterface;
import Proxy.MyFile;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Andreea
 */
public class Source extends AbstractSource{

    @Override
    public ArrayList<FileInterface> getData(ArrayList<FileInterface> files, String key) {
        File folder = new File("D:\\");
        files=new ArrayList<FileInterface>();
        List<File> list = new ArrayList<File>();
        getFiles(folder, list,files);
        return files;
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<FileInterface> getAfterSize(ArrayList<FileInterface> files, int min, int max) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    private static void getFiles(File folder, List<File> list,ArrayList<FileInterface> myFiles) {
        folder.setReadOnly();
        File[] files = folder.listFiles();
        for(int j = 0; j < files.length; j++) {      
            //System.out.println(files[j].getName());
            if(files[j].isDirectory()&&!files[j].isHidden())
                getFiles(files[j], list,myFiles);
            else{
                String name=files[j].getName();
                int index=name.lastIndexOf(".");
                String extension=name.substring(index+1,name.length());
                if (extension.equalsIgnoreCase("xml")&&files[j].length()<200){
                    MyFile f=new MyFile(files[j].getName(),files[j].length(),files[j].getAbsolutePath(),files[j].lastModified());
                    myFiles.add(f);
                    list.add(files[j]);
                }
            }
        }
    }
}
